package com.cz.kingdee.prod;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.cz.kingdee.KingdeeClient;
import com.cz.kingdee.dto.PrdMorpt;
import com.kingdee.bos.webapi.entity.OperateParam;
import com.kingdee.bos.webapi.entity.OperatorResult;
import com.kingdee.bos.webapi.entity.QueryParam;
import com.kingdee.bos.webapi.sdk.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 删除生产汇报单子
 */
public class DelPrdMorptByNumbers {

    public static void main(String[] args) throws Exception {
        KingdeeClient client = new KingdeeClient();
        //K3CloudApi k3CloudApi = client.getTestKingdeeClient();
        K3CloudApi k3CloudApi = client.getProdKingdeeClient();
        String mocNo = "MOCZ2501170011";
        QueryParam queryParam = new QueryParam();
        queryParam.setFormId("PRD_MORPT");
        queryParam.setFieldKeys("FID,FBillNo,FCreateDate,FDocumentStatus");
        queryParam.setFilterString("FMoBillNo ='"+mocNo+"'");
        List<PrdMorpt> result = k3CloudApi.executeBillQuery(queryParam, PrdMorpt.class);
        for (PrdMorpt prdMorpt : result) {
            String billNo = prdMorpt.getFBillNo();
            List<String> numbers = new ArrayList<>();
            numbers.add(billNo);

            OperateParam operateParam = new OperateParam();
            operateParam.setNumbers(numbers);
            OperatorResult operatorResult = null;
            try {
                operatorResult = k3CloudApi.unAudit("PRD_MORPT", operateParam);
                System.out.println("反审核:" +JSONUtil.toJsonStr(operatorResult.getResult().getResponseStatus()));
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                operatorResult = k3CloudApi.delete("PRD_MORPT", operateParam);
                System.out.println("删除:" +JSONUtil.toJsonStr(operatorResult.getResult().getResponseStatus()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }



}

